<?php 
require("../../config.php");
$conn = mysqli_connect($host, $user, $password, $dbname);
require("../../function.php");
$config = $bluestar->get_config($conn);
$user_info = $bluestar->detection($conn);
$isadmin = strpos($user_info["status"], "admin") !== false;
if (!$isadmin) {
    $bluestar->add_log($conn, "无权限访问admin面板", "", $_SERVER['REMOTE_ADDR'], time(), "200");
    header('Location: ../');
    exit;
}

?>
<link rel="stylesheet" href="../../file/css/mdui.min.css">
<script src="../../file/js/mdui.min.js"></script>
<div class="mdui-p-a-5 mdui-typo">
    <h2>官网信息</h2>
    <p>官网信息配置</p>
    <div class="mdui-textfield mdui-textfield-floating-label">
        <label class="mdui-textfield-label">网站名</label>
        <input class="mdui-textfield-input" />
    </div>
    <div class="mdui-textfield mdui-textfield-floating-label">
        <label class="mdui-textfield-label">简介</label>
        <textarea class="mdui-textfield-input"></textarea>
    </div>
    <button class="mdui-btn mdui-ripple mdui-btn-raised mdui-color-theme-accent mdui-m-t-4">保存更改</button>
</div>
<script>
    !function () {
        fetch("../?type=func&target=get_config", {
            method: "POST"
        }).then(v => v.json()).then(v => {
            mdui.$("input").val(v.data.websitename);
            mdui.$("textarea").val(v.data.about.split("<br>").join("\n"));
            mdui.updateTextFields()
            mdui.$("button").on("click", function () {
                mdui.$.ajax({
                    url: "../?type=func&target=set_config_about",
                    method: "POST",
                    data: {
                        value: mdui.$("textarea").val().split("\n").join("<br>")
                    },
                    success: function () {
                        mdui.$.ajax({
                            url: "../?type=func&target=set_config_websitename",
                            method: "POST",
                            data: {
                                value: mdui.$("input").val()
                            },
                            success: function () {
                                window.has_change = null;
                                window.top.mdui.snackbar("保存成功", { position: "left-bottom" })
                            }
                        })
                    }
                })
            });
            mdui.$("input").on("input", function () {
                window.has_change = () => true;
            });
            mdui.$("textarea").on("input", function () {
                window.has_change = () => true;
            });
        });
    }();
</script>